/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gravity;

import processing.core.PApplet;
import processing.core.PVector;

/**
 *
 * @author user
 */
public class SpaceObject {


    PApplet parent;
    PVector location;
    PVector velocity;
    PVector acceleration;
    
    float mass;
    float drawRadius;

    public SpaceObject(PApplet parent, PVector a, PVector v, PVector l, float m, float dR) {
        this.parent = parent;
        this.acceleration = a.get();
        this.velocity = v.get();
        this.location = l.get();
        this.mass = m;
        this.drawRadius = dR;
    }

    public void display() {
        parent.stroke(255);
        parent.noFill();
        parent.ellipseMode(PApplet.CENTER);
        parent.ellipse(this.location.x, this.location.y, 2 * drawRadius, 2 * drawRadius);
        GraphicsLibrary.drawVector(parent, location, velocity, GraphicsLibrary.VELOCITY_VECTOR_SCALE_FACTOR);        

    }

    public void update() {
        velocity.add(acceleration);
        location.add(velocity);
        acceleration.mult(0);
    }

    public void applyForce(PVector force) {
        force.div(mass);            // Newton's second law
        acceleration.add(force);    // Accumulate acceleration
    }

  public PVector calcGravForce(SpaceObject s) {
  PVector dir = PVector.sub(location, s.getLocation());        // Calculate direction of force
  float d = dir.mag();                              // Distance between objects
  dir.normalize();                                  // Normalize vector (distance doesn't matter, we just want direction)
  float force = (SystemSimulator.largeG * mass * s.getMass()) / (d * d); // Calculate gravitional force magnitude
  dir.mult(force);                                  // Get force vector --> magnitude * direction
  return dir;
}

    public PVector getAcceleration() {
        return acceleration;
    }

    public void setAcceleration(PVector acceleration) {
        this.acceleration = acceleration;
    }

    public float getDrawRadius() {
        return drawRadius;
    }

    public void setDrawRadius(float drawRadius) {
        this.drawRadius = drawRadius;
    }

    public PVector getLocation() {
        return location;
    }

    public void setLocation(PVector location) {
        this.location = location;
    }

    public float getMass() {
        return mass;
    }

    public void setMass(float mass) {
        this.mass = mass;
    }

    public PApplet getParent() {
        return parent;
    }

    public void setParent(PApplet parent) {
        this.parent = parent;
    }

    public PVector getVelocity() {
        return velocity;
    }

    public void setVelocity(PVector velocity) {
        this.velocity = velocity;
    }

    
}
